<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：何为摆动序列，即将递增或递减坡度上的数给删除了，剩下的就是摆动序列
      局部最优：删除单调坡上的节点。
      但是有三种特殊情况：
     
      */
      var wiggleMaxLength = function (nums) {
        if (nums.length < 2) {
          return nums.length
        }
        let curdiff = 0
        let prediff = 0
        //初始值默认为1,不考虑右边界
        let result = 1
        for (let i = 0; i < nums.length - 1; i++) {
          curdiff = nums[i + 1] - nums[i]
          if ((prediff <= 0 && curdiff > 0) || (prediff >= 0 && curdiff < 0)) {
            result++
            prediff = curdiff
          }
        }
        return result
      }
    </script>
  </body>
</html>
